{include file="public/header" /}

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>大{$Think.lang.ds_member_manage}</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

    <form id='Wechat_form' method="post" action="{:url('Member_da/add')}">
            <table class="ds-default-table">
                <tbody>
               
                    <tr class="noborder"> 
                        <td class="required w150"><label class="validation" for="">手机号&&大客户账号:</label></td>
                        <td class="vatop rowform"><input  name="member_name" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                    <tr class="noborder">
                        <td class="required w150"><label class="validation" >密码:</label></td>
                        <td class="vatop rowform"><input  name="member_password" value="" class="input-txt w400" type="password"></td>
                        <td class="vatop tips"></td>
                    </tr>
                    <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >大客户昵称:</label></td>
                        <td class="vatop rowform"><input  name="member_nickname" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                    <tr class="noborder">
                        <td class="required w150"><label class="validation" >大客户类型:</label></td>
                        <td class="vatop rowform">
                            <select name="member_da_type_id" >
                                <?php if(isset($memberda_type_info)&&!empty($memberda_type_info)){ ?>
                                <?php foreach($memberda_type_info as $vo ){?>
                                <option value="{$vo.id}">{$vo.title}</option>
                                <?php } ?>
                                <?php } ?>
                            </select>
                        </td>
                        <td class="vatop tips"></td>
                    </tr>
                  <!--   <tr class="noborder"> 
                      <td class="required w150"><label class="validation" for="wx_AppSecret">手机号:</label></td>
                      <td class="vatop rowform"><input  name="wx_AppSecret" value="" class="input-txt w400" type="text"></td>
                      <td class="vatop tips"></td>
                  </tr> -->
                    <tr class="noborder"> 
                        <td class="required w150"><label class="validation" for="">QQ号:</label></td>
                        <td class="vatop rowform"><input  name="member_qq" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                     <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >用户头像:</label></td>
                        <td class="vatop rowform"><input  name="file" id='upload_img'  type="file">
                         <input type="hidden" name="portrait" id='portrait'>
                        </td>
                        <td class="vatop tips">请上传后缀名为：*.jpeg *.jpg *.png 的文件</td>
                    </tr>
                    <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >企业名称:</label></td>
                        <td class="vatop rowform"><input  name="enterprise_name" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >企业类型:</label></td>
                        <td class="vatop rowform">
                         <select name="enterprise_type_id" id="">
                             <?php if(isset($enterprisetype_info)&&!empty($enterprisetype_info)){ ?>
                             <?php foreach($enterprisetype_info as $vo ){?>
                             <option value="{$vo.id}">{$vo.name}</option>
                             <?php } ?>
                             <?php } ?>
                         </select>
                        </td>
                        <td class="vatop tips"></td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >企业营业执照:</label></td>
                        <td class="vatop rowform">
                         <input  name="file" id='upload_pic'  type="file">
                         <input type="hidden" name="license" id='license'>
                        </td>
                        <td class="vatop tips">请上传后缀名为：*.jpeg *.jpg *.png 的文件</td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >联系人职位:</label></td>
                        <td class="vatop rowform"><input  name="contact_title" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >联系姓名:</label></td>
                        <td class="vatop rowform"><input  name="contact_name" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >联系方式:</label></td>
                        <td class="vatop rowform"><input  name="contact_phone" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >企业座机:</label></td>
                        <td class="vatop rowform"><input  name="contact_landline" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                      <tr class="noborder"> 
                        <td class="required w150"><label class="validation" >联系地址:</label></td>
                        <td class="vatop rowform"><input  name="contact_address" value="" class="input-txt w400" type="text"></td>
                        <td class="vatop tips"></td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr class="tfoot">
                        <td colspan="15"><input class="btn" type="submit" value="{$Think.lang.ds_submit}" style='line-height: 30px;'/></td>
                    </tr>
                </tfoot>
            </table>
    </form>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $('#Wechat_form').validate({
            errorPlacement: function(error, element) {
                error.appendTo(element.parent().parent().find('td:last'));
            },
            rules: {
                member_name : {
                    required: true,
                    minlength:11,
                    maxlength:11,
                    digits:true,
                  //  isMobile:true
                },
                member_password : {
                    required: true,
                    minlength:6,
                    maxlength:20,
                },
                member_nickname : {
                    required: true,
                    maxlength:8,
                },
                member_qq : {
                    required: true,
                    digits:true,
                    minlength:5,
                },
               /* portrait : {
                    required: true,
                },*/
                enterprise_name :{
                    required: true,
                },
                 enterprise_type_id : {
                    required: true,
                },
              /*  license : {
                    required: true,
                },*/
                contact_title : {
                    required: true,
                },
                contact_name : {
                    required: true,
                },
                contact_phone :{
                    required: true,
                    minlength:11,
                    maxlength:11,
                    digits:true,
                  //  isMobile:true
                },
                contact_landline : {
                    required: true,
                },
                contact_address :{
                    required: true,
                }
            },
            messages: {
                member_name : {
                required: "不能为空",
                minlength:"请填写11位的手机号",
                maxlength:"请填写11位的手机号",
                digits:"请填写正确的手机号码"

                },
                member_password : {
                    required: "不能为空",
                    minlength:"请设置长度为6-20位的密码",
                    maxlength:"请设置长度为6-20位的密码",

                },
                member_nickname : {
                    required: '不能为空',
                    maxlength:"昵称最长8位",
                },
                member_qq : {
                    required: '不能为空',
                    digits : '请输入正确的QQ号',
                    minlength:"请输入正确的QQ号",
                },
               /* portrait : {
                    required: '请上传用户头像',
                },*/
                enterprise_name :{
                    required: '不能为空',
                },
                enterprise_type_id : {
                    required: '不能为空',
                },
                /*license : {
                    required: '请上传营业执照',
                },*/
                contact_title : {
                    required: '不能为空',
                },
                contact_name : {
                    required: '不能为空',
                },
                contact_phone :{
                    required: '不能为空',
                    minlength:"请填写11位的手机号",
                    maxlength:"请填写11位的手机号",
                    digits:"请填写正确的手机号码"

                },
                contact_landline : {
                    required: '不能为空',
                },
                contact_address :{
                    required: '不能为空',
                }
            }
        });
     
     $('form').submit(function(){
         var res = $(this).valid();
         var portrait = $("#portrait").val();
        if(portrait ==''){
            layer.msg('请上传用户头像');return false;
        }
         var license = $("#license").val();
         if(license ==''){
            layer.msg('请上传营业执照');return false;
        }
         if(res){
             var url = $('form').attr('action');
             $.ajax({
                 type: "POST",
                 url: url,              
                 data: $('form').serialize(),
                 error: function (request) {
                     alert("Connection error");
                 },
                 success: function (result) {
                    // alert(result) ;return false;
                     if (result.code == 0) {
                         layer.msg(result.msg);
                         setTimeout(()=>{
                         location.href = result.url;
                         return false;
                         },1000)
                       
                     }else if(result.code == -1){
                         layer.msg(result.msg);return false;
                     } else{
                         layer.msg(result.msg);
                         setTimeout(()=>{
                         location.href = result.url;
                         return false;
                         },1000)
                       

                     }
                 }
             });
             return false;


         }else{
             return false;
         }
         return false;

     });


    });



                //用户头像上传
                  $(document).on('change','#upload_img',function() {
                      var files = document.getElementById('upload_img').files[0];
                      var formData = new FormData();
                      formData.append('file',files);
                      layer.msg('正在上传，请稍后');
                      $.ajax({
                          //请求方式
                          type : "POST",
                          //请求地址
                          url : "ajax_upload",
                          data : formData,
                          cache:false,  //默认是true，但是一般不做缓存
                          processData:false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                          contentType:false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                          //请求成功
                          success : function(result) {
                              if(result.err==0){
                                  layer.msg(result.msg);
                                  $('#portrait').val(result.data);
                              }else{
                                  $('#portrait').val('');
                                  alert('文件信息错误,请重新上传');return false;
                              }



                          },
                          //请求失败，包含具体的错误信息
                          error : function(e){
                              console.log(e.status);
                              console.log(e.responseText);
                          }
                      });

                  });

                   //营业执照上传
                  $(document).on('change','#upload_pic',function() {
                      var files = document.getElementById('upload_pic').files[0];
                      var formData = new FormData();
                      formData.append('file',files);
                      layer.msg('正在上传，请稍后');
                      $.ajax({
                          //请求方式
                          type : "POST",
                          //请求地址
                          url : "ajax_upload",
                          data : formData,
                          cache:false,  //默认是true，但是一般不做缓存
                          processData:false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                          contentType:false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                          //请求成功
                          success : function(result) {
                              if(result.err==0){
                                  layer.msg(result.msg);
                                  $('#license').val(result.data);
                              }else{
                                  $('#license').val('');
                                  alert('文件信息错误,请重新上传');return false;
                              }

                          },
                          //请求失败，包含具体的错误信息
                          error : function(e){
                              console.log(e.status);
                              console.log(e.responseText);
                          }
                      });

                  });

</script>






